﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using S4Store.Domain.FinancialReport;
using S4Store.Domain.TelSaleKpi;

namespace S4Store.Service
{
    public class TelSaleReportService : BaseService
    {
        public StoreReport GetStoreReport(int year, int month, int storeid)
        {
            TelSaleKpiService TelSaleKpiService = new Service.TelSaleKpiService();
            this.GetTranstion().Inject(TelSaleKpiService);
            StoreReport report = new StoreReport();
            report.DayDatas = TelSaleKpiService.GetCarBrandTelSaleDayDatas(year, month, storeid, true).ToList();
            report.MonthConfigs = TelSaleKpiService.GetCarBrandTelSaleMonthConfig(year, month, storeid, true).ToList();
            report.Standard = TelSaleKpiService.GetTelSaleKpiStandard(year, month, storeid);
            DateTime dt = new DateTime(year, month, 1).MonthLastOrNow();
            report.Year = dt.Year;
            report.Month = dt.Month;
            report.Day = dt.Day;
            return report;
        }

        public CarBrandReport GetCarBrandReport(int year, int month, int storeid, int carbrandid)
        {
            TelSaleKpiService TelSaleKpiService = new Service.TelSaleKpiService();
            CarService CarService = new Service.CarService();
            this.GetTranstion().Inject(TelSaleKpiService);
            this.GetTranstion().Inject(CarService);
            CarBrandReport report = new CarBrandReport();
            report.MonthConfig = TelSaleKpiService.GetCarBrandTelSaleMonthConfig(year, month, storeid, true).FirstOrDefault(t => t.CarBrandId == carbrandid);
            if (report.MonthConfig == null)
            {
                report.MonthConfig =new CarBrandTelSaleMonthConfig
                {
                    Month = new DateTime(year, month, 1).MonthLastOrNow(),
                    CarBrandId = carbrandid,
                    StoreId = storeid
                };
            }
            report.DayDatas = TelSaleKpiService.GetCarBrandTelSaleDayDatas(year, month, storeid, true).Where(t => t.CarBrandId == carbrandid).ToList();
            report.Standard = TelSaleKpiService.GetTelSaleKpiStandard(year, month, storeid);
            DateTime dt = new DateTime(year, month, 1).MonthLastOrNow();
            report.Year = dt.Year;
            report.Month = dt.Month;
            report.Day = dt.Day;
            report.CarBrand = CarService.GetCarBrandQuery().FirstOrDefault(t => t.Id == carbrandid);
            return report;

        }
    }
}
